package com.yunfei.api.v2;

import com.yunfei.api.v2.contants.QueryHeTongSignInfoContant;
import com.yunfei.api.v2.param.ContractIdParam;
import com.yunfei.api.v2.param.LongTokenParam;
import com.yunfei.api.v2.param.getBase64.GetBase64Param;
import com.yunfei.api.v2.param.heTongDownLoad.HeTongDownLoadParam;
import com.yunfei.api.v2.param.personMoulage.PersonMoulageParam;
import com.yunfei.api.v2.param.uploadFileCreateContract.UploadFileCreateContractParam;
import com.yunfei.api.v2.result.LookHeTongSignStatusJson.LookHeTongSignStatusJson;
import com.yunfei.api.v2.result.getBase64Moulage.GetBase64MoulageJson;
import com.yunfei.api.v2.result.queryHeTongDetail.HeTongDetailResultJson;
import com.yunfei.api.v2.result.signReport.SignReportJson;
import com.yunfei.api.v2.service.*;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.utils.string.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 系统生成电子合同
 * @Author: zhengyunfei
 * @Date: 2018/6/15
 * @time:11:26
 */
@SuppressWarnings("ALL")
@RestController
@RequestMapping("/api/v2/yunhetong")
@Api(value = QueryHeTongSignInfoContant.YUNHETONG_NAMESPACE,tags =  QueryHeTongSignInfoContant.YUNHETONG_NAMESPACE )
public class YunHeTongApiController {

    @Autowired
    private DownLoadContractService downLoadContractService;
    @Autowired
    private GetLongTokenService getLongTokenService;
    @Autowired
    private HTSGetDetailService htsGetDetailService;
    @Autowired
    private YunContractGetStatusService yunContractGetStatusService;
    @Autowired
    private YunContractSignReportService yunContractSignReportService;
    @Autowired
    private DownLoadContractSignReportService downLoadContractSignReportService;
    @Autowired
    private CreatePersonMoulageService createPersonMoulageService;
    @Autowired
    private UploadFileCreateContractService uploadFileCreateContractService;
    /**
     * @Description: 上传文件生成合同
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/contract/fileContract")
    @ApiOperation(position = 3,value = QueryHeTongSignInfoContant.fileContract,notes = QueryHeTongSignInfoContant.fileContract,response = ResultModel.class)
    @ResponseBody
    public Object fileContract(UploadFileCreateContractParam param){
        ResultModel resultModel=new ResultModel();
        resultModel=uploadFileCreateContractService.uploadFileCreateContract(param);
        return resultModel;
    }
    /**
     * @Description: 合同下载
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/download/contract")
    @ApiOperation(position = 3,value = QueryHeTongSignInfoContant.DOWNLOAD_CONTRACT,notes = QueryHeTongSignInfoContant.DOWNLOAD_CONTRACT_NOTES,response = ResultModel.class)
    @ResponseBody
    public Object downloadContract(HeTongDownLoadParam param){
        ResultModel resultModel=new ResultModel();
        String idType=param.getIdType();
        if(StringUtil.isNullOrEmpty(idType)){
            param.setIdType("0");
        }
        resultModel=downLoadContractService.downloadContract(param);
        return resultModel;
    }
    /**
     * @Description:合同作废-合同下载
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/download/contractCancel")
    @ApiOperation(position = 3,value = QueryHeTongSignInfoContant.DOWNLOAD_CONTRACT_ZUOFEI,notes = QueryHeTongSignInfoContant.DOWNLOAD_CONTRACT_ZUOFEI,response = ResultModel.class)
    @ResponseBody
    public Object downloadContractCancel(HeTongDownLoadParam param,ContractIdParam contractIdParam){
        ResultModel resultModel=new ResultModel();
        String idType=param.getIdType();
        if(StringUtil.isNullOrEmpty(idType)){
            param.setIdType("0");
        }
        resultModel=downLoadContractService.downloadContractCancel(param,contractIdParam);
        return resultModel;
    }
    /**
     * @Description: 查看合同详情接口
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/contract/detail")
    @ApiOperation(position = 3,value = QueryHeTongSignInfoContant.LOOK_CONTRACT_DETAIL,notes = QueryHeTongSignInfoContant.LOOK_CONTRACT_DETAIL,response = HeTongDetailResultJson.class)
    @ResponseBody
    public Object detail(ContractIdParam param){
        ResultModel resultModel=new ResultModel();
        resultModel=htsGetDetailService.getDetail(param);
        return resultModel.getData();
    }
    /**
     * @Description: 查看合同状态
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/contract/status")
    @ApiOperation(position = 3,value = QueryHeTongSignInfoContant.LOOK_CONTRACT_STATUS,notes = QueryHeTongSignInfoContant.LOOK_CONTRACT_STATUS,response = LookHeTongSignStatusJson.class)
    @ResponseBody
    public Object status(ContractIdParam param){
        ResultModel resultModel=new ResultModel();
        resultModel=yunContractGetStatusService.getStatus(param);
        return resultModel.getData();
    }
    /**
     * @Description: 查看合同签署报告
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/contract/signReport")
    @ApiOperation(position = 3,value = QueryHeTongSignInfoContant.LOOK_CONTRACT_SIGNREPORT,notes = QueryHeTongSignInfoContant.LOOK_CONTRACT_SIGNREPORT,response = SignReportJson.class)
    @ResponseBody
    public Object signReport(ContractIdParam param){
        ResultModel resultModel=new ResultModel();
        resultModel=yunContractSignReportService.signReport(param);
        return resultModel.getData();
    }
    /**
     * @Description: 合同签署报告下载
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/download/signReport")
    @ApiOperation(position = 3,value = QueryHeTongSignInfoContant.DOWNLOAD_CONTRACT_SIGNREPORT,notes = QueryHeTongSignInfoContant.DOWNLOAD_CONTRACT_SIGNREPORT,response = SignReportJson.class)
    @ResponseBody
    public Object downloadSignReport(HeTongDownLoadParam param){
        ResultModel resultModel=new ResultModel();
        resultModel=downLoadContractSignReportService.download(param);
        return resultModel.getData();
    }
    /**
     * @Description: 创建个人印章
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/user/personMoulage")
    @ApiOperation(position = 3,value = QueryHeTongSignInfoContant.USER_PERSON_MODUAGE,notes = QueryHeTongSignInfoContant.USER_PERSON_MODUAGE_NOTES,response = SignReportJson.class)
    @ResponseBody
    public Object personMoulage(PersonMoulageParam param){
        ResultModel resultModel=new ResultModel();
        resultModel=createPersonMoulageService.createPersonMoulage(param);
        return resultModel.getData();
    }
    /**
     * @Description: 创建个人印章
     * @Author: zhengyunfei
     * @Date: 2019/7/29
     * @time:10:30
     */
    @PostMapping(value="/user/moulage/getBase64")
    @ApiOperation(position = 3,value = QueryHeTongSignInfoContant.GET_BASE64_MOULAGE,notes = QueryHeTongSignInfoContant.GET_BASE64_MOULAGE,response = GetBase64MoulageJson.class)
    @ResponseBody
    public Object personMoulage(GetBase64Param param,LongTokenParam longTokenParam){
        ResultModel resultModel=new ResultModel();
        resultModel=createPersonMoulageService.getBase64Moulage(param,longTokenParam);
        return resultModel.getData();
    }
}
